﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MediaRegister
{

    public partial class FormUpplåsning : Form
    {

        private struct upplåsning
        {
            public string Modell;
            public string Operator;
            public string ImeiNr;
            public string Datum;
        }

        public int up1;
        public FormUpplåsning()
        {
            InitializeComponent();
        }
        public FormUpplåsning(int up)
        {
            up = up1;
            InitializeComponent();
        }

        private void Add_Click(object sender, EventArgs e)
        {
            upplåsning upp1;

            upp1.Modell = Model.Text;
            upp1.ImeiNr = textBox2.Text;
            upp1.Operator = textBox3.Text;
            upp1.Datum = textBox4.Text;
            FileStream fs1 = new FileStream(@"M:\upplåsning.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sr1 = new StreamWriter(fs1);
            sr1.WriteLine(upp1.Modell + " , " + upp1.Operator + " , " + upp1.ImeiNr + " , " + upp1.Datum);
            foreach (Control t in this.Controls)
                if (t is TextBox)
                    t.Text = " ";
            sr1.Close();
        }

        private void ShowFile_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            String s1;
            if (File.Exists(@"M:\upplåsning.txt"))
            {
                FileStream fs1 = new FileStream(@"M:\upplåsning.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr1 = new StreamReader(fs1);
                s1 = sr1.ReadLine();
                while (s1 != null)
                {
                    listBox1.Items.Add(s1);
                    s1 = sr1.ReadLine();


                }
                sr1.Close();
            }

            else
            {
                MessageBox.Show("Finns ingen fil att visa");
            }
        }
    }
}